package com.example.mystoryapp2.ui.main.fragments

import android.content.Intent
import androidx.lifecycle.ViewModelProvider
import android.os.Bundle
import android.view.View
import com.example.mystoryapp2.R
import com.example.mystoryapp2.contexts.StoryContext
import com.example.mystoryapp2.databinding.FragmentAuthorHomeBinding
import com.example.mystoryapp2.ui.base.BaseFragment
import com.example.mystoryapp2.ui.story.create.CreateStoryActivity
import com.example.mystoryapp2.ui.story.storylist.StoryListActivity

class AuthorHomeFragment : BaseFragment<FragmentAuthorHomeBinding>() {

    companion object {
        fun newInstance() = AuthorHomeFragment()
    }

    private lateinit var viewModel: AuthorHomeViewModel

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        viewModel = ViewModelProvider(this).get(AuthorHomeViewModel::class.java)
        mDataBinding.viewModel = viewModel
    }

    override fun getLayoutId(): Int {
        return R.layout.fragment_author_home
    }

    override fun onInitView(view: View) {
        mDataBinding.btnCreate.setOnClickListener { createStory() }
        mDataBinding.btnUnpublished.setOnClickListener { unPublishedStory() }
        mDataBinding.btnPublished.setOnClickListener { publishedStory() }
    }

    private fun createStory(){
        activity?.let { CreateStoryActivity.startCreateInstance(it) }
    }

    private fun publishedStory(){
        activity?.let { StoryListActivity.startPublished(it) }
    }

    private fun unPublishedStory(){
        activity?.let { StoryListActivity.startUnPublished(it) }
    }

}